<?php

/**
 * @author ducnhat
 * @email ddnhat@gmail.com
 * @copyright 2014
 */
 
class Admin_AuthController extends Zenddn_Controller_Action{
	
	public function init(){
		parent::init();
        parent::loadTemplate('alpona');
        $this->_helper->layout->setLayout('login');
        $this->view->headTitle = "login";
	}
	
	public function indexAction(){
		$auth = Zend_Auth::getInstance();
        
        if($auth->hasIdentity()){
            echo "<br /> Bạn đã đăng nhập!<br />";
        }else{
            echo "<br /> Bạn chưa đăng nhập!<br />";
        }
	}
    
    public function loginAction(){
        $request = $this->_request;
        
        $error = false;
        
        if($request->isPost()){
            $auth = new Zenddn_System_Auth();
            
            $result = $auth->login($request->getParams());
            
            if($result){
                
                $info = new Zenddn_System_Info();
                
                $info->createInfo();
                
                $this->_redirect('/admin/index');
            }else{
                $error = true;
            }            
        }
        
        $this->view->isError = $error;
    }
    
    public function logoutAction(){
        $auth = Zend_Auth::getInstance();
        $auth->clearIdentity();
        
        $info = new Zenddn_System_Info();
        $info->destroyInfo();
        
        $this->_helper->_redirector->gotoRoute(array('module' => 'admin', 'controller' => 'auth', 'action' => 'index'), null, true);
    	$this->_helper->viewRenderer->setNoRender();
    }
}